package com.ruoyi.system.mapper;

import java.util.List;
import java.util.Map;

import com.ruoyi.system.domain.DyUserinfo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 用户卡信息Mapper接口
 * 
 * @author ruoyi
 * @date 2024-04-25
 */
@Mapper
public interface DyUserinfoMapper 
{
    @Select("SELECT DISTINCT ref_url from dy_userinfo")
    public List<String> getAllDomain();
    public List<DyUserinfo> selectDyUserinfoListByIds(@Param("ids") List<Long> ids);
    @Select(" update dy_userinfo " +
            "    set is_online=0 " +
            "  where is_online=1 " +
            "    and online_last_time<=DATE_SUB(NOW(), INTERVAL ${seconds} SECOND)")
    public void updateLastOnlineOffLine(Integer seconds);
    @Select("<script>" +
            "  <if test=\"type==1\">" +
            "  SELECT rq, count(*) as num FROM (" +
            "   SELECT DISTINCT DATE_FORMAT(creat_time, '%Y-%m-%d') as rq,ip " +
            "     FROM dy_userinfo " +
            "    WHERE creat_time>=CONCAT(DATE_SUB(CURDATE(), INTERVAL 6 DAY), ' 00:00:00') " +
            "  ) xy GROUP BY rq " +
            "  </if>" +
            "  <if test=\"type==2\">" +
            "  SELECT rq, count(*) as num FROM (" +
            "   SELECT DATE_FORMAT(creat_time, '%Y-%m-%d') as rq" +
            "     FROM dy_userinfo " +
            "    WHERE creat_time>=CONCAT(DATE_SUB(CURDATE(), INTERVAL 6 DAY), ' 00:00:00') " +
            "  ) xy GROUP BY rq " +
            "  </if>" +
            "</script>")
    public List<Map<String, Object>> getStatisCount(int type);

    @Select(" update dy_userinfo set is_exp=1 where id=${id}")
    public void updateExp(Long id);
    @Select("<script>" +
            "  <if test=\"type==1\">" +
            "   SELECT count(*) " +
            "     FROM (" +
            "       SELECT ip " +
            "         FROM dy_userinfo " +
            "        WHERE creat_time>=CONCAT(SUBSTRING(CAST(NOW() AS CHAR), 1, 10), ' 00:00:00') " +
            "       GROUP BY ip " +
            "    ) a" +
            "  </if>" +
            "  <if test=\"type==2\">" +
            "   SELECT count(*) " +
            "     FROM dy_userinfo " +
            "    WHERE creat_time>=CONCAT(SUBSTRING(CAST(NOW() AS CHAR), 1, 10), ' 00:00:00') " +
            "  </if>" +
            "  <if test=\"type==3\">" +
            "   SELECT count(*) " +
            "     FROM dy_userinfo " +
            "  </if>" +
            "  <if test=\"type==4\">" +
            "   SELECT count(*) " +
            "     FROM dy_userinfo" +
            "    WHERE status not in (100,200,400)" +
            "  </if>" +
            "</script>")
    public int getCount(int type);
    /**
     * 查询用户卡信息
     * 
     * @param id 用户卡信息主键
     * @return 用户卡信息
     */
    public DyUserinfo selectDyUserinfoById(Long id);


    @Select(" SELECT * " +
            "   FROM dy_userinfo " +
            "  WHERE order_id=#{orderId} " +
            "  order by id desc " +
            "  limit 1")
    public DyUserinfo selectDyUserinfoByOrderId(String orderid);

    /**
     * 查询用户卡信息列表
     * 
     * @param dyUserinfo 用户卡信息
     * @return 用户卡信息集合
     */
    public List<DyUserinfo> selectDyUserinfoList(DyUserinfo dyUserinfo);

    /**
     * 新增用户卡信息
     * 
     * @param dyUserinfo 用户卡信息
     * @return 结果
     */
    public int insertDyUserinfo(DyUserinfo dyUserinfo);

    /**
     * 修改用户卡信息
     * 
     * @param dyUserinfo 用户卡信息
     * @return 结果
     */
    public int updateDyUserinfo(DyUserinfo dyUserinfo);

    /**
     * 删除用户卡信息
     * 
     * @param id 用户卡信息主键
     * @return 结果
     */
    public int deleteDyUserinfoById(Long id);

    /**
     * 批量删除用户卡信息
     * 
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteDyUserinfoByIds(Long[] ids);

    public int overDyUserinfoByIds(Long[] ids);
}
